//
//  LineSkectchMode.m
//  dataGathering
//
//  Created by macmini on 15/3/16.
//  Copyright (c) 2015年 shuili. All rights reserved.
//

#import "LineSkectchMode.h"

@interface LineSkectchMode ()
@property(nonatomic, retain)AGSPoint* beginPoint;

@end

@implementation LineSkectchMode

-(instancetype)initWithMapview :(AGSMapView*)mapview
{
    return [super initWithMapview:mapview];
}

-(void)mapView:(AGSMapView *)mapView didTapAndHoldAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features
{
    self.myGraphic = [[AGSGraphic alloc] initWithGeometry:mappoint symbol:self.innerSymbol attributes:nil];
    [self.myGraphicsLayer addGraphic:self.myGraphic];
    _beginPoint = mappoint;
    [self.myPolyline addPointToPath:mappoint];
    
}

-(void)mapView:(AGSMapView *)mapView didMoveTapAndHoldAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features
{
    NSLog(@"moving");
    
    [self.myPolyline addPointToPath:mappoint];
    
    [self.myGraphic setGeometry:self.myPolyline];
    
}

-(void)mapView:(AGSMapView *)mapView didEndTapAndHoldAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features
{
    NSLog(@"end");
    
    [self.myPolyline addPointToPath:mappoint];
    
    [self.myGraphic setGeometry:self.myPolyline];
    
    //[self stop];
    
    //if (self.delegate && [self.delegate respondsToSelector:@selector(BaseMode:didFinishDrawing::)]) {
    //    [self.delegate BaseMode:self didFinishDrawing:self.myPolyline :@"POLYLINE"];
    //}
}

-(void)mapView:(AGSMapView *)mapView didClickAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features
{
    
    if([[AGSGeometryEngine defaultGeometryEngine] geometry:mappoint intersectsGeometry:self.myPolyline])
    {
        [self stop];
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(BaseMode:didFinishDrawing::)]) {
            [self.delegate BaseMode:self didFinishDrawing:self.myPolyline :@"POLYLINE"];
        }
    }
}

@end
